Skip to content

Fix list subclass + list and copy() returning the subclass - #1354

Open
jseop-lim wants to merge 1 commit into
oracle:masterfrom
jseop-lim:fix/list-concat-exact-list
Open

jseop-lim wants to merge 1 commit into
oracle:masterfrom
jseop-lim:fix/list-concat-exact-list

Conversation

@jseop-lim

Copy link
Copy Markdown
Contributor

Description

Part of #1291 (item 9).

ListBuiltins.ConcatNode and ListCopyNode allocate their result with GetClassForNewListNode, which returns the receiver's class for a PList. CPython returns an exact list from both (list_concat, list_copy_impl).

AS-IS

>>> class L(list): pass
...
>>> type(L([1]) + [2])
<class '__main__.L'>
>>> type(L([1]).copy())
<class '__main__.L'>

TO-BE

>>> type(L([1]) + [2])
<class 'list'>
>>> type(L([1]).copy())
<class 'list'>

(matching CPython)

Changes

  • Create an exact list in ConcatNode and ListCopyNode, and remove GetClassForNewListNode, which has no other user.
  • Add a test to tests/test_list_subclassing.py.

Testing

mx python-jvm on darwin-aarch64, then mx graalpytest on test_list_subclassing.py (the new test fails on the unpatched build and passes with the fix) and the tagged test_list (60 passed). mx python-checkcopyrights, mx eclipseformat and mx checkstyle are clean.

For a list subclass, + and copy() returned an instance of the subclass.
CPython returns an exact list from both.

Signed-off-by: Jeongseop Lim <jeongseop_lim@korea.ac.kr>
@oracle-contributor-agreement oracle-contributor-agreement Bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Nov 25, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

OCA Verified All contributors have signed the Oracle Contributor Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant